<?php
/*
<application>PHP ASSERTION UNIT</application>
<version>1.1<</version>
<author>D. Fournier</author>
<e-mail>zenon48@users.sourceforge.net</e-mail>
<copyright>2002 ID EST</copyright>
<license>GPL</license>
<filename>assert.mod</filename>
<documentation></documentation>
*/
define('AT_WARN', 0);

/*
################################
ASSERT_Tester class
Role: setting the assertion
Instantiator: Assert global variable
################################
*//*c)class*/class
ASSERT_Tester
{
var
/*string[]*/$asserts;

/*f)void*/function
ASSERT_Tester(
/*a)argtype*/
){
$this->asserts = array(
	"Assert.warn(%s,%s);",	///JavaScript Assert method calling templates
	"Assert.%s(%s);",
	"Assert.%s(%s,%s);",
	"Assert.%s(%s,%s,%s);",
	"Assert.%s(%s,%s,%s,%s);");
}	//---ASSERT_Tester constructor

/*m)private any*/function
setWithQuote(
/*any*/$arg
){
if(is_null($arg)) return 'null';
if($this->isWithoutQuote($arg)) return $arg;
/*string*/$value = str_replace('"', '\\"', $arg);
$value = str_replace("'", "\\'", $value);
return "\"$value\"";
}	//---setWithQuote

/*boolean*//*f)void*/function
setJsScript(
/*a)string*/$script
){
echo "<script language=\"JavaScript\">\n", $script, "\n</script>\n";
}	//---setJsScript

/*m)private any*/function
getDoItString(
/*a)string*/$doIt
){
return is_string($doIt) ? $this->setWithQuote($doIt) : ($doIt ? 'true' : 'false');
}	//---getDoItString

/*m)private boolean*/function
isWithoutQuote(
/*string*/$arg
){
return is_numeric($arg) || is_bool($arg);
}	//---isWithoutQuote

/*m)public void*/function
setCheck(
/*a)int*/$template,
/*a)string*/$assertion,
/*a)any*/$arg0,
/*a)boolean*/$arg1,		//)doIt || id
/*a)string*/$arg2		//)id
){
$this->setJsScript(sprintf($template, $assertion, $this->setWithQuote($arg0), $this->getDoItString($arg1), $this->setWithQuote($arg2)));
}	//---setCheck

/*m)public void*/function
setCompare(
/*a)int*/$template,
/*a)string*/$assertion,
/*a)any*/$arg0,
/*a)any*/$arg1,
/*a)boolean*/$arg2,		//)doIt || id
/*a)string*/$arg3		//)id
){
$this->setJsScript(sprintf($template, $assertion, $this->setWithQuote($arg0), $this->setWithQuote($arg1), $this->getDoItString($arg2), $this->setWithQuote($arg3)));
}	//---setCompare

/*m)public void*/function
isTrue(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isTrue', $arg0, $doIt, $id);
}	//---isTrue

/*m)public void*/function
isFalse(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isFalse', $arg0, $doIt, $id);
}	//---isFalse

/*m)public void*/function
isNull(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isNull', $arg0, $doIt, $id);
}	//---isNull

/*m)public void*/function
isNotNull(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isNotNull', $arg0, $doIt, $id);
}	//---isNotNull

/*m)public void*/function
isUndefined(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isUndefined', $arg0, $doIt, $id);
}	//---isUndefined

/*m)public void*/function
isNotUndefined(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isNotUndefined', $arg0, $doIt, $id);
}	//---isNotUndefined

/*m)public void*/function
isNumber(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isNumber', $arg0, $doIt, $id);
}	//---isNumber
/*m)public void*/function
isNotNumber(
/*a)any*/$arg0,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCheck($this->asserts[func_num_args()], 'isNotNumber', $arg0, $doIt, $id);
}	//---isNotNumber

/*m)public void*/function
isEqual(
/*a)any*/$arg0,
/*a)any*/$arg1,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCompare($this->asserts[func_num_args()], 'isEqual', $arg0, $arg1, $doIt, $id);
}	//---isEqual

/*m)public void*/function
isNotEqual(
/*a)any*/$arg0,
/*a)any*/$arg1,
/*a)boolean*/$doIt=TRUE,
/*a)string*/$id=FALSE
){
$this->setCompare($this->asserts[func_num_args()], 'isNotEqual', $arg0, $arg1, $doIt, $id);
}	//---isNotEqual

/*m)public void*/function
warn(
/*a)string*/$warning,
/*a)boolean*/$doIt=TRUE
){
$this->setJsScript(sprintf($this->asserts[AT_WARN], $this->setWithQuote($warning), $this->getDoItString($doIt)));
}	//---warn

}	//---ASSERT_Tester

/*ASSERT_Tester*/$Assert = new ASSERT_Tester();
?>

